//
//  SchoolDetailBottomView.swift
//  HoneyBee
//
//  Created by point on 2018/6/10.
//  Copyright © 2018年 point. All rights reserved.
//

import UIKit

protocol SchoolDetailBottomViewTDelegate : class {
    func clickAction(_ type:SchoolDetailBottomViewType)
}

enum SchoolDetailBottomViewType{
    case comment , tel , collection , appointment
}

class SchoolDetailBottomView: UIView {
    
    weak var delegate : SchoolDetailBottomViewTDelegate?
    
    /// 点击评论按钮
    fileprivate lazy var  commentBtn: UIButton = UIButton(type: .custom)
    /// 电话
    lazy var  telBtn: UIButton = UIButton(type: .custom)
    /// 收藏
     lazy var  collectionBtn: UIButton = UIButton(type: .custom)
    /// 预约
     lazy var  appointmentBtn: UIButton = UIButton(type: .custom)
    
  
    
   
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
}

// MARK:- 交互逻辑
extension SchoolDetailBottomView {
    @objc func clickCommentBtn(btn:UIButton) {
        delegate?.clickAction(.comment)
    }
    
    @objc func clickTelBtn(btn:UIButton) {
        delegate?.clickAction(.tel)
    }
    
    @objc func clickcollectionBtn(btn:UIButton) {
        delegate?.clickAction(.collection)
    }
    
    @objc func clickAppointmentBtn(btn:UIButton) {
        delegate?.clickAction(.appointment)
    }
}


// MARK:- 设置UI
extension SchoolDetailBottomView {
    fileprivate func setupUI(){
      
        addSubview(commentBtn)
        addSubview(telBtn)
        addSubview(collectionBtn)
        addSubview(appointmentBtn)
        
        let lineView = UIView()
        addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.left.top.right.equalTo(self)
            make.height.equalTo(0.5)
        }
        lineView.backgroundColor = nC1
        
        
        commentBtn.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(40)
           make.size.equalTo(CGSize(width: 35, height: 35))
            make.centerY.equalTo(self)
        }
      
        commentBtn.addTarget(self, action: #selector(clickCommentBtn(btn:)), for: .touchUpInside)
        commentBtn.setImage(UIImage(named: "school_comment"), for: .normal)
        
        telBtn.snp.makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp.right).offset(40)
            make.size.equalTo(CGSize(width: 35, height: 35))
            make.centerY.equalTo(self)
        }
   
        telBtn.addTarget(self, action: #selector(clickTelBtn(btn:)), for: .touchUpInside)
        telBtn.setImage(UIImage(named: "school_tel"), for: .normal)
        collectionBtn.snp.makeConstraints { (make) in
            make.left.equalTo(telBtn.snp.right).offset(40)
            make.size.equalTo(CGSize(width: 35, height: 35))
            make.centerY.equalTo(self)
        }
     
        collectionBtn.addTarget(self, action: #selector(clickcollectionBtn(btn:)), for: .touchUpInside)
         collectionBtn.setImage(UIImage(named: "school_collection"), for: .normal)
        appointmentBtn.setTitle("预约试听", for: .normal)
        appointmentBtn.snp.makeConstraints { (make) in
            make.right.equalTo(self).inset(20)
            make.jSize(CGSize(width: 100, height: 35))
            make.centerY.equalTo(self)
        }
        appointmentBtn.addTarget(self, action: #selector(clickAppointmentBtn(btn:)), for: .touchUpInside)
        appointmentBtn.backgroundColor = UIColor.init(hex: "888896") //8a8a8a
        appointmentBtn.fastCornerRadius(value: 4)
    }
}
